<template>
  <div class="myDiv">
    <div style="margin: 155px 300px">
      <table>
        <tr>
          <td>
            <div style="width: 360px;">
              <h2 style="color:blue;">5G新零售</h2>
              <h2 style="color:blue;">新体验 新生态 新场景 新边界</h2>
            </div>
          </td>
          <td>
            <div style="margin-left: 325px;"></div>
          </td>
          <td>
            <!-- 上 右 下 左 -->
            <div class="login">
              <div class="title">登录</div>
              <form class="login-form">
                <div class="form-input-block">
                  <div class="line" style="position: relative;">
                    <i class="el-icon-user login-icon"></i>
                    <input type="text" v-model = "username" placeholder="请输入用户名" id="username" />
                  </div>
                  <div class="line" style="position: relative;">
                    <i class="el-icon-unlock login-icon"></i>
                    <input type="password" v-model = "password" placeholder="请输入密码" id="password" />
                  </div>
                  <input type="text" maxlength="4" placeholder="请输入右侧结果" id="checkCode" />
                  <!--<img class="codeImg" id="checkCodeImg" title="点击更换验证码" src="/login/getCheckCode" />-->
                  <div class="error-info" style="display: none">密码错误</div>
                </div>
                <div class="form-option" style="margin-left: -108px; margin-bottom: 38px">
                  <label>
                    <span class="fake-checkbox">
                      <i></i>
                      <input type="checkbox" id="keepLogin" />
                    </span> 7天内自动登录
                  </label>
                </div>
                <el-button type="primary" round @click="onLogin">登录</el-button>
              </form>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
  import {get, post} from '@/api/http.js'

  export default {
    name: "login",

    // 方法区
    methods: {
      // 登录
      onLogin(){
        let param = {"username": this.username, "password": this.password};
        get("/admin/auth/login.do", param)
          .then(res =>{
            this.$store.commit("setToken", res.data.token);
            localStorage.setItem('userName', res.data.userName);
            this.$router.push("/home");
          })
          .catch(err =>{
            console.info(err);
          })
          .finally(() =>{})
      }
    },

    data() {
      return {
        username:'',
        password:'',
      }
    }
  }
</script>

<style scoped>

  .login-form .error-info {
    color: #f44336;
    font-size: 14px;
    left: 16px;
    bottom: 9px;
  }

  .login .form-input-block .codeImg{
    width:72px;
    height:32px;
    opacity:1;
    bottom: 40px;
    right: 10px;
  }

  .login .form-input-block #checkCode{
    background: none;
    padding-left: 16px;
    width: 220px;
  }

  .login .login-icon {
    position: absolute;
    top: 6px;
    left: 45px;
    font-size: 29px;
  }

  .login .form-input-block input {
    width: 177px;
    height: 38px;
    line-height: 48px;
    border: 1px solid rgba(224, 224, 224, 1);
    border-radius: 6px;
    padding-left: 59px;
    margin-bottom: 20px;
    outline: 0
  }

  .login .title {
    width: 100px;
    height: 45px;
    font-size: 32px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 55px;
    color: #409EFF;
    opacity: 1;
    margin-bottom: 40px;
  }

  .login {
    width: 300px;
    height: 400px;
    background-color: white;
    border-radius: 16px
  }

  .myDiv {
    background-image: url("../../assets/login1.jpg");
    background-size: cover;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 106%;
  }
</style>
